package com.youlai.boot.modules.blog.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.boot.common.annotation.Log;
import com.youlai.boot.common.enums.LogModuleEnum;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import com.youlai.boot.modules.blog.service.BlogService;
import com.youlai.boot.system.model.entity.Archives;
import com.youlai.boot.system.model.query.ArchivesQuery;
import com.youlai.boot.system.model.query.DictDataPageQuery;
import com.youlai.boot.system.model.vo.ArchivesVO;
import com.youlai.boot.system.model.vo.DictDataPageVO;
import com.youlai.boot.system.model.vo.ProjectVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@Tag(name = "博客展示页")
@RestController
@RequestMapping("/api/v1/blog")
@RequiredArgsConstructor
@Slf4j
public class BlogController {

    private final BlogService blogService;

    @Operation(summary = "博客文章列表")
    @GetMapping("/archives")
    public PageResult<ArchivesVO> getArchivesPage(ArchivesQuery queryParams) {
        IPage<ArchivesVO> result = blogService.getArchivesPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "博客文章列表")
    @GetMapping("/projects")
    public PageResult<ProjectVO> getProjectPage() {
        IPage<ProjectVO> result = blogService.getProjectPage();
        return PageResult.success(result);
    }

    @Operation(summary = "查询分类类别")
    @GetMapping("/categories")
    public PageResult<DictDataPageVO> getDictDataPage(
            DictDataPageQuery queryParams
    ) {
        Page<DictDataPageVO> result = blogService.getDictDataPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "查询最近3篇文章")
    @GetMapping("/top3")
    public Result<ArrayList<Archives>> getArchivesTop3(){
        return Result.success(blogService.getArchivesTop3());
    }

    @Operation(summary = "根据文章ID查询文章内容")
    @GetMapping("/getArchivesById/{aid}")
    public Result<ArchivesVO> getArchivesById(@Parameter(description = "文章ID") @PathVariable Long aid) {
        return Result.success(blogService.getArchivesById(aid));
    }
}